package exception;
/**异常处理机制中的try-catch*/
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始执行...");

        try {
            //String line=null;
            String line = "abcdef";
            System.out.println(line.length());
            System.out.println(line.charAt(3));
            System.out.println(Integer.parseInt(line));
        /*} catch (NullPointerException e) {
            System.out.println("发生 NullPointerException: line 为 null！");
        }catch(StringIndexOutOfBoundsException e){
            System.out.println("发生 StringIndexOutOfBoundsException: line 的长度为 3，索引为 5 超出了范围！");
        }*/
        }catch(NullPointerException|StringIndexOutOfBoundsException e){
            System.out.println("发生了空指针异常或下标越界异常，并且解决了！");
        }catch(Exception e){
            System.out.println("发生了异常,并且解决了！");
        }
        System.out.println("程序执行结束...");
    }
}
